package com.yang.controller;


import com.yang.domain.Result;
import com.yang.domain.entity.Link;
import com.yang.service.LinkService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 后台友联链接控制层
 * </p>
 * @author yang
 * @date 2023/5/29
 */
@RestController
@RequestMapping("/content/link")
public class LinkController {

    @Resource
    private LinkService linkService;

    @GetMapping("/list")
    public Result finAllLinkList(Link link, Integer pageNum,Integer pageSize){
        return linkService.finAllLinkList(link,pageNum,pageSize);
    }

    @PostMapping
    public Result addLink(@RequestBody Link link){
        return linkService.addLink(link);
    }

    @PutMapping
    public Result editLink(@RequestBody Link link){
        return linkService.editLink(link);
    }

    @DeleteMapping("/{id}")
    public Result removeLink(@PathVariable(value = "id") Long id){
        return linkService.removeLink(id);
    }

    @PutMapping("/changeLinkStatus")
    public Result changeLinkStatus(@RequestBody Link link){
        return linkService.editLink(link);
    }

    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable(value = "id") Long id){
        Link link = linkService.getById(id);
        return Result.okResult(link);
    }
}
